from __future__ import division
from operator import itemgetter, attrgetter
from struct import *
import gc
import math
import os
import random
import sys
import time
from sets import Set
from random import randint
import re
import numpy as np
from os import walk

ifn = "/home/vgc/wei/workspace/NYU_IRTK/data/unigramFromWei/documentPostingArrays/gov2/GOV2_DocumentPostingArray_WHOLE_20140702_pt_2DTableFromTOP100Postings.binary"
inputFileHandler0 = open(ifn,"rb")

statinfo = os.stat(ifn)
fileSize = statinfo.st_size
print "currentInputFileName: ",ifn
print "file size:",fileSize
numOfBytesRead = 0
numOfDocumentsProcessed = 0
while numOfBytesRead < fileSize:
	byteString = inputFileHandler0.read(4 + 4)
	(docID,numOfPostings) = unpack( "2I", byteString)
	print "docID:",docID,numOfPostings
	for i in range(0,numOfPostings):
		byteString = inputFileHandler0.read(4 + 4 + 4 + 4 + 4)
		(termID,static,dynamic,combined,score1) = unpack( "1I4f", byteString)
		# print "----->",i,termID,static,dynamic,combined,score1
		print "----->",i,termID,static,dynamic,combined,score1
		# print "----->",i,termIDANDTermDict[termID],termID,static,dynamic,combined,score1
		if docID == 1:
			exit(1)
			numOfDocumentsProcessed += 1
			numOfBytesRead += 8 + score1 * 4 * 5
			inputFileHandler0.close()
			print "Ends."
			exit(1)
